/* Copyright (C) 2009 Vlad Roubtsov. All rights reserved. */

#if defined (__GNUC__)
#   include <cxxabi.h>
#   include <stdlib.h>
#endif

#include "vr/exception/exceptions.hpp"

#include "vr/util/utility.hpp"

using namespace vr;

//----------------------------------------------------------------------------
namespace vr
{
namespace utility
{

std::string
as_class_name (const std::string & s)
{
#if defined (__GNUC__)

    int status = 0;
    char * demangled = abi::__cxa_demangle (s.c_str(), 0, 0, & status);
    if (status == 0 && demangled)
    {
      std::string result (demangled);
      ::free (demangled);

      return result;
    }

    __VR_THROW_X (std::domain_error, "failed to demangle [" + s + "]");

#else
#   warning "no demangling is available with this compiler"

    return s;
#endif
}

} // end of 'utility'
} // end of namespace
//----------------------------------------------------------------------------
